package buggy;

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws java.io.IOException {

		int num1 = readInteger();
		System.out.println("\nYou entered the integer: " + num1);

		int num2 = reverseDigits(num1);

		int result = squaredDiffReversedNumber(num1, num2);

		System.out.println("The computed result is: " + result);
	}

	/* Obtain the squared difference of num1 and num2 */
	private static int squaredDiffReversedNumber(int num1, int num2) {
		C1 o1 = new C1(num1, num2);
		C2 o2 = new C2(num1, num2);

		int result1 = o1.compute();
		int result2 = o2.compute();

		return result1 * result2;
	}

	/* Reverse the digits of the number */
	/* Fix the bug of negative number */
	private static int reverseDigits(int number) {
		int reversedNumber = 0;
		int temp = 0;
		boolean negative = false;
		if (number < 0)
			negative = true;
		number = Math.abs(number);

		while (number > 0) {

			temp = number % 10;

			reversedNumber = reversedNumber * 10 + temp;
			number = number / 10;

		}
		if (negative == true)
			number = -number;
		return reversedNumber;
	}

	private static int readInteger() throws java.io.IOException {

		String s1;
		String s2;
		int num = 0;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		boolean cont = true;

		while (cont) {

			System.out.print("Enter an integer:");
			s1 = br.readLine();
			StringTokenizer st = new StringTokenizer(s1);
			s2 = "";

			while (cont && st.hasMoreTokens()) {
				s2 = st.nextToken();
				num = Integer.parseInt(s2);
				cont = false;
			}
		}
		return num;
	}
}
